package com.hspedu.poly;

import com.hspedu.Super.A;

public class dynamic_ {

    public static void main(String[] args) {
        //a的编译类型A,运行类型B
        AA a = new B();//向上转型
        System.out.println(a.sum());//?40->30
        System.out.println(a.sum1());//?30->20
    }
}

    class AA {//父类
        public int i = 10;
        //动态绑定机制:
        public int sum() {//父类sum()
            return getI() + 10;//20+10
        }
        public int sum1 () {//父类 sum1()
            return i + 10;//10 + 10
        }
        public int getI () {//父类 getI
            return i;
        }
    }

class B extends AA {//子类
    public int i = 20;

//    public int sum() {
//        return i + 20;
//    }

    public int getI() {//子类 getI()
        return i;
    }

//    public int sum1() {
//        return i + 10;
//    }
}
